﻿@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Common.Enums.InsuranceWarranty
@using ZBJF.Warranty.WebProvider
@using EnumHelper = ZBJF.Warranty.Common.Common.EnumHelper
@using ZBJF.Warranty.Common.Enums.InfoCollect
@model ZBJF.Warranty.Model.InsuranceWarrantyRecord
@{
    ViewBag.Title = "分拣中工单-查看基本信息";
    var hasBlendRules = ServiceFactory.InsuranceWarrantyBendTheRulesRecordServiceInstance.IsExist(Model.ID, (byte)BendTheRulesWithType.RemotePartitionBendTheRules);
}
@Html.HiddenFor(m => m.ID)
@Html.HiddenFor(m => m.InsuranceOrderId)
<!--物流信息-->
@RenderPage("/Views/WorkOrderCommonInfo/InsuranceWarrantyRecordExpressInfo.cshtml", new { insuranceWarrantyRecordID = Model.ID, ExpressSendByWhoType = (byte)ExpressSendByWhoType.UserSendToPartitionCenter })

@RenderPage("~/Views/WorkOrderCommonInfo/InfoCollectItems.cshtml", new { CollectWithType = (byte)CollectWithType.PartitionCenterCollet })

@RenderPage("~/Views/WorkOrderCommonInfo/AuditInfo.cshtml", new { AuditProjectType = (byte)AuditProjectType.SortingCenter })

<!--通融安排与历史-->
@RenderPage("~/Views/WorkOrderCommonInfo/BendTheRuleRecordForm.cshtml", new { BendTheRulesWith = (byte)BendTheRulesWithType.PartitionCenterBendTheRules })
@RenderPage("~/Views/WorkOrderCommonInfo/InsuranceWarrantyBendTheRulesRecordInfo.cshtml",new{ BendTheRulesWith = (byte)BendTheRulesWithType.PartitionCenterBendTheRules})

<h4>维修安排</h4>
<div id="serviceProviderBranchMain">
    <div class="search-panel">
        @Html.HiddenFor(m => m.SortingCenterID)
        @Html.HiddenFor(m => m.ServiceProviderBranchId)
        <h5>维修安排：请在下方选定一家需使用的服务商</h5>
        <label>配件</label>
        @Html.DropDownList("AccessoriesTypeID", ZBJF.Warranty.WebProvider.ConvertToSelector.Instance.AccessoriesTypeConvertToSelectList(Model.InsuranceOrder.ProductTypeId ?? 0, addEmptySelect: false))
        <label>配件品质</label>
        @Html.DropDownList("AccessoriesLevelID", ZBJF.Warranty.WebProvider.ConvertToSelector.Instance.AccessoriesLevelConvertToSelectList(addEmptySelect: false))
        <label>所在省</label>@Html.DropDownList("ProviderBranchProvinceID", ZBJF.Warranty.WebProvider.ConvertToSelector.Instance.D_ProvinceConvertToSelectList(addEmptySelect: false), new {@class = "Province"})
        <label>所在市</label>
        <select name="ProviderBranchCityID" id="ProviderBranchCityID"></select>
        <input type="button" class="btn btn-primary" value="查询" onclick="searchProviderBranch()"/>
    </div>
    <table class="table table-responsive table-bordered table-hover" id="tabServiceProviderBranch">
        <thead>
            <tr>
                <th>选择</th>
                <th>所属服务商</th>
                <th>网点名称</th>
                <th>维修报价</th>
                <th>所在省</th>
                <th>所在市</th>
                <th>详细地址</th>
            </tr>
        </thead>
    </table>
</div>
<div>
    <label class="text">
        锁屏密码：@Html.DropDownListFor(n => n.LockScreenTypeID, ZBJF.Warranty.WebProvider.ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(LockScreenTypeEnums)))&nbsp;&nbsp;
        @Html.TextBoxFor(n => n.LockScreenContent)
    </label>
</div>
@if (ServiceFactory.InsuranceWarrantyRecordStatusServiceInstance.GetParentStatusCode(Model.Status) == (byte) InsuranceWarrantyStatus.InSorting)
{
    <div class="form-actions text-center">
        <input class="btn btn-primary Edit-R" type="button" onclick="Save(1)" value="保存信息">
        <input class="btn btn-primary Edit-R" type="button" onclick="Save(2)" value="提交维修">
        <input class="btn btn-primary Edit-R" type="submit" value="拒赔" onclick="showIWRRefuseLayer()">
        <input class="btn" type="button" value="取消报案" id="btnCancel">
    </div>
}
@*---------------取消报案--------------*@
<div id="showCancelReport">
    <table style="margin: 0 auto; line-height: 50px;">
        <tr>
            <th>请选择取消原因：</th>
            <td>@Html.DropDownList("StatusReasonCancel", ConvertToSelector.Instance.StatusReasonConvertToSelectList(true, ((byte)InsuranceWarrantyStatus.Canceled)))</td>
        </tr>
    </table>
</div>
<script src="/Scripts/uploadAdapter/jquery.loadscript.js"></script>
<script src="/Scripts/uploadAdapter/jquery.uploadAdapter.js"></script>
<script src="/Scripts/WarrantyRecord/warrantyRecord.js"></script>
<script>
    $(function () {
        $("#showCancelReport").hide();//隐藏div
        $("#tabServiceProviderBranch").dataTable({
            "sAjaxSource": "/WorkOrderCommonInfo/ServiceProviderBranchList?AccessoriesTypeID=" + $("#AccessoriesTypeID").val() + "&AccessoriesLevelID=" + $("#AccessoriesLevelID").val() + "&provinceId=" + $("#ProviderBranchProvinceID").val() + "&CityId=" + $("#ProviderBranchCityID").val() +"&ServiceType=@Model.WarrantyMaintenanceTypeID"  + "&ProductModelId=@Model.InsuranceOrder.ProductModelId",
            aoColumns: [
                {
                    "mData": null,
                    "bSortable": false,
                    "fnRender": function (nRow) {
                        return '<input type="radio" name="ServiceProviderBranch" class="CheckBoxItem" ' + ("@(Model.ServiceProviderBranchId)" == nRow.aData.ServiceProviderBranchID ? "checked" : "") + ' value="' + nRow.aData.ServiceProviderBranchID + '" onclick="checkServiceBranch(this)"/>';
                    }
                },
                { "mData": "ServiceProviderName", "bSortable": false },
                { "mData": "ServiceProviderBranchName", "bSortable": false },
                { "mData": "QuotationPrice", "bSortable": false },
                { "mData": "ProvinceName", "bSortable": false },
                { "mData": "CityName", "bSortable": false },
                { "mData": "Address", "bSortable": false }
            ]
        });
    });


            //保存信息
            function Save(saveType) {
                var auditInfoForm = $('#auditInfoForm').serializeJson();//审核信息
                var param = $.extend({}, auditInfoForm);//多个表单参数拼接
                var serviceProviderBranchId = $("#ServiceProviderBranchId").val();
                var lockScreenTypeID = $("#LockScreenTypeID").val();
                var lockScreenContent = $("#LockScreenContent").val();



                var obj = $("#tabServiceProviderBranch").find(":radio:checked");
                var serviceProviderName = $(obj).parent().siblings().eq(0).html();
                var serviceProviderBranchName = $(obj).parent().siblings().eq(1).html();
                var quotationPrice = $(obj).parent().siblings().eq(2).html();
                param.LockScreenTypeID = lockScreenTypeID;
                param.LockScreenContent = lockScreenContent;
                param.ServiceProviderName = serviceProviderName;
                param.ServiceProviderBranchId = serviceProviderBranchId;
                param.ServiceProviderBranchName = serviceProviderBranchName;
                param.Status = "@Model.Status";

                if (serviceProviderBranchId == "") {
                    layer.alert("请选择维修服务商");
                    return;
                }
                if (saveType == 2 && parseFloat(quotationPrice) > parseFloat("@Model.InsuranceOrder.InsuredAmount")) {//验证报价是否超过保额
                    layer.alert("维修报价大于保额@(Model.InsuranceOrder.InsuredAmount)，请选择其他维修商");
                    return;
                }

                if (saveType == 2) {//提交维修
                    //验证信息收集
                    var infoCollectComplete = true;
                    $(".InfoCollectCanUploadPicCount").each(function () {
                        //需要上传的图片数大于已经上传的图片数则视为没有完成信息收集
                        if ($(this).text() >
                            $("#" + $(this).attr("id").replace("InfoCollectCanUploadPicCount", "InfoCollectHadUploadPicCount"))
                            .text())
                            infoCollectComplete = false;
                    });
                    if (!infoCollectComplete) {
                        layer.alert("请完成信息收集！");
                        return;
                    }
                    //验证审核信息
                    if (!$("#auditInfoForm").valid()) {
                        layer.alert("请选择审核结果！");
                        return;
                    }
                }
                layer.load();
                $.ajax({
                    url: "/SortingWorkOrder/SaveSortingCenterAuditInsuranceWarrantyRecord?ID=@Model.ID" + "&saveType=" + saveType,
                    type: "Post",
                    data: param,
                    success: function (data) {
                        layer.alert(data.Message, {
                            end: function () {
                                layer.closeAll();
                                if (data.Success) {
                                    layer.load();
                                    location.reload();
                                }
                            },
                            yes: function () {
                                layer.closeAll();
                                if (data.Success) {
                                    layer.load();
                                    location.reload();
                                }
                            }
                        });
                    }
                });
            }
            var index;
            //取消报案
            $("#btnCancel").click(function() {
                index = layer.open({
                    type: 1,
                    title: '请选择取消报案原因', //标题栏
                    closeBtn: false,
                    area: '600px;',
                    shade: 0.8,
                    id: 'LAY_layuipro', //设定一个id，防止重复弹出
                    resize: false,
                    btn: ['确认', '取消'],
                    btnAlign: 'c', //按钮排列
                    yes: function(index, layero) {
                        UpdateInsuranceWarrantyRecordStatus();
                    },
                    moveType: 1, //拖拽模式，0或者1
                    content: $('#showCancelReport').show()
                });
            });
            //取消报案点击确定后修改状态
            function UpdateInsuranceWarrantyRecordStatus() {
                var statusReasonId = $("#StatusReasonCancel").val();
                if (!statusReasonId) {
                    layer.alert("请选择取消报案原因");
                }
                var stauts = @((byte) InsuranceWarrantyStatus.Canceled);
                $.ajax({
                    url: "/ToBeMaintainWorkOrder/UpdateInsuranceWarrantyRecordStatus?ID=" + @Model.ID,
                    dataType: "json",
                    type: "GET",
                    data: { statusReasonId: statusReasonId, status: stauts },
                    success: function(data) {
                        if (data.Result) {
                            layer.close(index);
                            layer.alert(data.Message);
                            return;
                        }
                    }
                });
            }

            function showIWRRefuseLayer() {
                layer.open({
                    type: 2,
                    title: '请选择拒赔原因',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['820px', '400px'],
                    content: '/ToBeMaintainWorkOrder/IWRRefuse?insuranceWarrantyRecordId=@Model.ID '+'&infoCollectWithType=@((byte)CollectWithType.PartitionCenterCollet)'+'&auditProjectType=@((byte)AuditProjectType.SortingCenter)'
                });
            }
</script>